import 'package:intl/intl.dart';

class CallRecord {
  final String id;
  final String deviceId;
  final String deviceName;
  final DateTime startTime;
  final DateTime endTime;
  final int duration;
  final String status;

  CallRecord({
    required this.id,
    required this.deviceId,
    required this.deviceName,
    required this.startTime,
    required this.endTime,
    required this.duration,
    required this.status,
  });

  factory CallRecord.fromJson(Map<String, dynamic> json) => CallRecord(
    id: json['id'] as String,
    deviceId: json['deviceId'] as String,
    deviceName: json['deviceName'] as String,
    startTime: DateTime.parse(json['startTime'] as String),
    endTime: DateTime.parse(json['endTime'] as String),
    duration: json['duration'] as int,
    status: json['status'] as String,
  );

  Map<String, dynamic> toJson() => {
    'id': id,
    'deviceId': deviceId,
    'deviceName': deviceName,
    'startTime': DateFormat('yyyy-MM-dd HH:mm:ss').format(startTime),
    'endTime': DateFormat('yyyy-MM-dd HH:mm:ss').format(endTime),
    'duration': duration,
    'status': status,
  };
}